<?php
/*
    HerbalWorkshop. Web database of herbals and oils, recipes and their effects.
    Copyright (C) 2009  Nikolay Gniteev godhart@gmail.com

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

	//Define autoload method for classes
	function __autoload($class_name) {
		require_once $class_name . '.cls';
	}
		
	//Load user settings
	include_once 'settings.inc';	//TODO: make it user depended
	
	//Load environment (it's settings depended)
	include_once 'environment.inc';	
	
	// Load Visualisation Template
	$viz = new Blitz("$Templates/form_test.tpl");
	
	// Load Forms Template
	$forms = new Blitz_Forms("$Templates/forms.tpl");
	
	$form_parser = new Form_Parser();
	$form = array (
	'> "Hello World"',
	"> \"Line 2\"\n> \"Line 3\"", 
	'_> "Line 4 on Line 3"', 
	'> "Line 5"');
	
	$form_parser->Load($form);
	
	$form_data = "";
	$form_data = '<h1>Parsed:</h1>';
	foreach ($form_parser->Debug_Parsed as $line)
	{ $form_data .= $line . '<br>'; }
	
	$form_data .= '<h1>Unparsed:</h1>';	
	foreach ($form_parser->Debug_Unparsed as $line)
	{ $form_data .= $line . '<br>'; }
	
	$form_data .= '<h1>Form Test:</h1>';

	$form_data .= '<form action="form_action" 
	method="post" 
	enctype="multipart/form-data" 
	target="_parent">';
	
    $form_data .= '<BUTTON name="submit" value="submit" type="submit">';
//    $form_data .= 'button_text(submit)';
    $form_data .= '<IMG src="button_img_path" alt="button_text(submit)">';
    $form_data .= '</BUTTON>';

    $form_data .= '<BUTTON name="reset" value="reset" type="reset">';
//    $form_data .= 'button_text(submit)';
    $form_data .= '<IMG src="button_img_path" alt="button_text(reset)">';
    $form_data .= '</BUTTON>';

    $form_data .= '<BUTTON name="button_name" value="button_value" type="button">';
//    $form_data .= 'button_text(submit)';
    $form_data .= '<IMG src="button_img_path" alt="button_text(button)">';
    $form_data .= '</BUTTON>';

	$form_data .= '<FIELDSET><LEGEND>Fieldset1</LEGEND>';	

	$form_data .= '<input type="hidden" name="entry_hidden" value="hidden_value">';
	
	$form_data .= '<br><LABEL for="entry_text">entry_text_label</LABEL>';
	$form_data .= '<input type="text" name="entry_text" value="text_value" size="8" maxlength="16">';

	$form_data .= '<br><LABEL for="entry_password">entry_password_label</LABEL>';
	$form_data .= '<input type="password" name="entry_password" value="password_value" size="6" maxlength="16">';
	
	$form_data .= '</FIELDSET>';	
	$form_data .= '<FIELDSET><LEGEND>Fieldset2</LEGEND>';	

	$form_data .= '<br><LABEL for="entry_checkbox">entry_checkbox_label</LABEL>';
	$form_data .= '<input type="checkbox" name="entry_checkbox" value="checkbox_value" checked>';

	$form_data .= '<br><LABEL for="entry_group_0_radio_0">entry_group_0_radio_0_label</LABEL>';
	$form_data .= '<input type="radio" name="entry_group_0_radio" value="radio_value_0">';
	
	$form_data .= '<br><LABEL for="entry_group_0_radio_1">entry_group_0_radio_1_label</LABEL>';
	$form_data .= '<input type="radio" name="entry_group_0_radio" value="radio_value_1" checked>';

	$form_data .= '<br><LABEL for="entry_group_0_radio_2">entry_group_0_radio_2_label</LABEL>';
	$form_data .= '<input type="radio" name="entry_group_0_radio" value="radio_value_2">';

	$form_data .= '<br><LABEL for="entry_file">entry_file_label</LABEL>';
	$form_data .= '<input type="file" name="entry_file" value="file_value">';

	$form_data .= '<br><LABEL for="entry_textarea">entry_textarea_label</LABEL>';
	$form_data .= '<br><textarea name="entry_textarea" rows="2" cols="25">textarea_value</textarea>';	

	$form_data .= '<br><LABEL for="entry_select">entry_select_label</LABEL>';
	$form_data .= '
 <SELECT name="entry_select">
     <OPTION selected label="none" value="none">None</OPTION>
     <OPTGROUP label="group_0">
       <OPTION label="group_0_label_0" 
       			value="group_0_value_0">
       					 group_0_text_0</OPTION>
       <OPTION label="group_0_label_1" 
       			value="group_0_value_1">
       					 group_0_text_1</OPTION>
     </OPTGROUP>
     <OPTGROUP label="group_1">
       <OPTION label="group_1_label_0" 
       			value="group_1_value_0">
       					 group_1_text_0</OPTION>
       <OPTION label="group_1_label_1" 
       			value="group_1_value_1">
       					 group_1_text_1</OPTION>
     </OPTGROUP>
 </SELECT>
	';

	$form_data .= '<br><LABEL for="entry_select(mult)">entry_select(mult)_label</LABEL>';
	$form_data .= '
 <SELECT name="entry_select(mult)" multiple="true" size="3">
     <OPTGROUP label="group_0">
       <OPTION label="group_0_label_0" 
       			value="group_0_value_0">
       					 group_0_text_0</OPTION>
       <OPTION label="group_0_label_1" 
       			value="group_0_value_1">
       					 group_0_text_1</OPTION>
     </OPTGROUP>
     <OPTGROUP label="group_1">
       <OPTION label="group_1_label_0" 
       			value="group_1_value_0">
       					 group_1_text_0</OPTION>
       <OPTION label="group_1_label_1" 
       			value="group_1_value_1">
       					 group_1_text_1</OPTION>
     </OPTGROUP>
 </SELECT>
	';
	
	$form_data .= '</FIELDSET>';	
	$form_data .= '</form>';
	
	$regex = '/^\s*'.Form_Parser::quoted_regex.'/';
	$test_lines = array(
	' right_unquoted ',
	' " right_quoted1 " ',
	' `right_\\`guoted2` ',
	' " wrong_guoted ` ',
	' [ square braced ] ',
	' <angle \\>braced> ',
	' {qurly braced} ',
	' { badly braced ] ');
	
	//$form_data .= '<br>'.htmlentities($regex,true);
	foreach($test_lines as $test)
	{
		if(preg_match($regex,$test,$m))
		{
			$form_data.='<br>'.':'.htmlentities($m[1]);
			$form_data.='<br>'.'::'.var_export($m,true);
		}
	}
	echo $viz->parse(array('Form'=>array('content'=>$form_data)));
?>